import request from '@/utils/request'

const headers = {
  'Content-Type': 'application/json'
}

export function getMenusTreeByRole(data) {
  return request({
    url: 'api/menu/getMenusAndButtonByChooseroleId',
    method: 'post',
    data: JSON.stringify(data),
    headers
  })
}

export function getMenusTree() {
  return request({
    url: 'api/menu/getAllMenusAndButton',
    method: 'post',
    data: JSON.stringify({}),
    headers
  })
}

export function getRoleList(data) {
  return request({
    url: 'api/role/getList',
    method: 'post',
    data: JSON.stringify(data),
    headers
  })
}

export function add(data) {
  return request({
    url: 'api/role/add',
    method: 'post',
    data: JSON.stringify(data),
    headers
  })
}

export function del(data) {
  return request({
    url: 'api/role/delete',
    method: 'post',
    data: JSON.stringify(data),
    headers
  })
}

export function edit(data) {
  return request({
    url: 'api/role/update',
    method: 'post',
    data: JSON.stringify(data),
    headers
  })
}

export const getByRole = params => {
  return request({
    url: 'api/menu/getByRole',
    method: 'get',
    params
  })
}

export const getAllMenu = params => {
  return request({
    url: 'api/menu/all',
    method: 'get',
    params
  })
}

export const getElementByQry = data => {
  return request({
    url: 'api/element/getElementByQry',
    method: 'post',
    data: JSON.stringify(data),
    headers
  })
}

export const getByRoleAndMenu = data => {
  return request({
    url: 'api/element/getByRoleAndMenu',
    method: 'post',
    data: JSON.stringify(data),
    headers
  })
}

export const chooseElement = data => {
  return request({
    url: 'api/element/choose',
    method: 'post',
    data: JSON.stringify(data),
    headers
  })
}

export const delElementSelection = data => {
  return request({
    url: 'api/element/deleteSelection',
    method: 'post',
    data: JSON.stringify(data),
    headers
  })
}

export default { add, edit, del, getMenusTree }

